import express from 'express';
import path from 'path';
import cookieParser from 'cookie-parser';
import logger from 'morgan';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import cors from 'cors';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
// CORS配置
app.use(cors())
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// 前台
import indexRouter from './routes/index.js';
import usersRouter from './routes/users.js';

// 后台
import adminUserRouter from './routes/admin/user.js';
import adminFileRouter from './routes/admin/file.js';
import adminCategoryRouter from './routes/admin/category.js';
import adminArticleRouter from './routes/admin/article.js';
import adminLabelRouter from './routes/admin/label.js';
import adminDiaryRouter from './routes/admin/diary.js';
import adminShareRouter from './routes/admin/share.js';
import adminCommentRouter from './routes/admin/comment.js';
import adminMessageRouter from './routes/admin/message.js';
import adminOverViewRouter from './routes/admin/overview.js';


app.use(logger('dev'));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);

app.use('/admin/user', adminUserRouter);
app.use('/admin/file', adminFileRouter);
app.use('/admin/category', adminCategoryRouter);
app.use('/admin/article', adminArticleRouter);
app.use('/admin/label', adminLabelRouter);
app.use('/admin/diary', adminDiaryRouter);
app.use('/admin/share', adminShareRouter);
app.use('/admin/comment', adminCommentRouter);
app.use('/admin/message', adminMessageRouter);
app.use('/admin/overview', adminOverViewRouter);

export default app;
